home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Modules / schemedefs.em < prev    next >
Lisp/Scheme  |  1992-10-06  |  20KB  |  863 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2.  
  3. ; newschemedef.em
  4. ; Full Scheme definition module
  5. ; DDeR
  6. ; Last change
  7. ; Sat Nov 24 15:29:39 GMT 1990
  8.  
  9. ; NB This file is written in EuLisp.  Beware that some Scheme
  10. ; functions are visible as they are renamed on import, others 
  11. ; because they are defined here, but they shouldn't be used!  
  12. ; In principle, the renaming can occur on export.
  13.  
  14. ; BUGS:
  15. ; characters module not imported, when it is the functions don't exist
  16. ; mapcar doesn't exist
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. (defmodule schemedefs
  21.  
  22.   (;(import characters)
  23.  
  24.            ; Broken now...
  25.  
  26.        (except (error 
  27.            memq read read-char peek-char    ; for V0.37
  28.            max min oddp                ; for V0.37
  29.                    let
  30.            substring string vector string-append
  31.            char-upcase char-downcase vector write-char
  32.            last-pair
  33.            ) standard)
  34.  
  35.    (rename (
  36.  
  37.            ; NB new names are exported at the end of this module
  38.  
  39.         ;(characterp char?)                not exported in V0.37
  40.         ;(functionp procedure?)            missing in V0.37
  41.         (character-to-integer char->integer)    ; wrong name in V0.37
  42.         (char-equal char=?)
  43.         (char< char<?)
  44.         (char> char>?)
  45.         (char<= char<=?)
  46.         (char>= char>=?)
  47.         (char-upcase feel-char-upcase)
  48.         (char-downcase feel-char-downcase)
  49.         ;(character->integer char->integer)            ; instead
  50.         (consp pair?)
  51.         (symbolp symbol?)
  52.         (stringp string?)
  53.         (vectorp vector?)
  54.         (numberp number?)
  55.         (end-of-stream-p eof-object?)
  56.         (eq eq?) 
  57.         (equal equal?) 
  58.         (evenp even?)
  59.         (input-stream-p input-port?)
  60.         (integer-to-character integer->char)    ; wrong name in V0.37
  61.         ;(integer->character integer->char)            ; instead
  62.         ;(labels letrec) Bogus!!!
  63.         (last-pair last) ; broken on improper lists in V7.04
  64.         ;(list-length length)
  65.         ;(list-to-string list->string)
  66.         ;(mapcar map)
  67.         (negativep negative?)
  68.         (null null?)
  69.         (nconc append!)
  70.         ;(number-to-string number->string)         missing in V0.37
  71.         ;(oddp odd?)                 misfeature in V0.37
  72.         (output-stream-p output-port?)
  73.         ;(positivep positive?)             missing in V0.37
  74.         (prin display)
  75.         (standard-input-stream current-input-port)
  76.         (standard-output-stream current-output-port)
  77.         (string-append feel-string-append)
  78.         ;(string-slice substring)    already called substring in V0.37
  79.         (substring feel-substring)
  80.         (symbol-name symbol->string)
  81.         (make-symbol string->symbol)
  82.         (write-char feel-write-char)
  83.         (zerop zero?)
  84.  
  85.         ; these are name clashes and so we prefix them with eulisp-
  86.  
  87.         (error eulisp-error)
  88.  
  89.         ; these are V0.37 misfeatures
  90.  
  91.         (memq old-memq) ;            misfeature in V0.37
  92.         (read old-read) ;            misfeature in V0.37
  93.         (read-char old-read-char) ;        misfeature in V0.37
  94.         (peek-char old-peek-char) ;        misfeature in V0.37
  95.         (max old-max);            misfeature in V0.37
  96.         (min old-min);            misfeature in V0.37
  97.  
  98.         ) (except (let string vector) standard)))
  99.  
  100.   ()
  101.  
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MACROS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103.  
  104.  
  105.   (defmacro iterate (name binds . body)
  106.     `(labels
  107.        ((,name ,(mapcar (lambda (x) (car x)) binds) ,@body))
  108.        (,name ,@(mapcar (lambda (x) (cadr x)) binds))))
  109.  
  110.   (defmacro let (binds . body)
  111.     (if (symbol? binds)
  112.       `(iterate ,binds ,@body)
  113.       `((lambda ,(map car binds) ,@body)
  114.     ,@(map cadr binds))))
  115.  
  116.   (defmacro case (key . clauses)
  117.     (let ((keyvar '@case-keyvar@))
  118.       `(let ((,keyvar ,key))
  119.      (cond
  120.       ,@(map
  121.          (lambda (clause)
  122.            (let ((op (car clause))
  123.              (rest (cdr clause)))
  124.          (cond
  125.           ((eq? op 'else) clause)
  126.           (else
  127.            (let ((items (if (pair? op) op (list op))))
  128.              `((or ,@(map (lambda (th)
  129.                        `(eqv? ',th ,keyvar))
  130.                      items))
  131.                ,@rest))))))
  132.          clauses)))))
  133.  
  134.   (defmacro letrec (binds . body)
  135.     `(let ,(map 
  136.          (lambda (bind) 
  137.            `(,(car bind) '()))
  138.          binds)
  139.        ,@(map
  140.        (lambda (bind)
  141.          `(set! ,(car bind) ,@(cdr bind)))
  142.        binds)
  143.        ,@body))
  144.  
  145.   (defun filter (pred l)
  146.     (cond
  147.       ((null l) '())
  148.       ((pred (car l)) (cons (car l) (filter pred (cdr l))))
  149.       (t (filter pred (cdr l)))))
  150.         
  151.   (defmacro do (binds condn . body)
  152.     (let ((constant (filter (lambda (bind) (= (length bind) 2)) binds))
  153.       (stepped (filter (lambda (bind) (= (length bind) 3)) binds)))
  154.       `(let ,constant
  155.      (let do-loop 
  156.           ,(map 
  157.          (lambda (bind) (list (car bind) (cadr bind)))
  158.          stepped)
  159.        (if ,(car condn) (begin ,@(cdr condn))
  160.          (begin
  161.            ,@body
  162.            (do-loop 
  163.          ,@(map (lambda (bind) (caddr bind)) stepped))))))))
  164.  
  165.   (export let iterate case letrec labels do)
  166.  
  167.   (deflocal map mapcar)
  168.  
  169.   (export mapcar)
  170.  
  171. ;;;;;;;;;;;;;;;;;;;;; PATCH SECTION for V0.37 ;;;;;;;;;;;;;;;;;;;;;;;;;
  172.  
  173. (defun open-unschemed-input-file (file)
  174.   (let ((fd (popen (format () "/opt/home/kjp/Bin/unscheme < ~a" file) 'input)))
  175.     fd))
  176.  
  177. (export open-unschemed-input-file)
  178.  
  179. (deflocal *true* t)
  180. (deflocal *false* '())
  181.  
  182. (export *true* *false*)
  183.  
  184. (defun eqv? (x y)
  185.   (or (eq? x y)
  186.       (and (characterp x) (characterp y) (char-equal x y))
  187.       (and (numberp x) (numberp y) (= x y))))
  188.  
  189. (export eqv?)
  190. (export negative?)
  191.  
  192. (defun sorry dummy 
  193.   (eulisp-error "Sorry - unimplemented EuLisp function" schemedef-error))
  194.  
  195. ; These are in EuLisp but are missing in V0.37
  196.  
  197. ; (defun functionp (x) (eq (class-of x) function))
  198. ;(defun characterp (x) (eq (class-of x) character))
  199.  
  200. (defun positive? (x) (> x 0))
  201.  
  202. ;(defun abs (x) (if (< x 0) (- x) x))
  203.  
  204. (defun expt (b n)
  205.   (cond ((= n 0)   1)
  206.         ((evenp n) ((lambda (x) (* x x)) (exp b (/ n 2))))
  207.         (t         (* b (exp b (- n 1))))))
  208.  
  209. (defun number-to-string (n . radix)
  210.   (unless (null? radix)
  211.     (display "number-to-string: ignoring radix\n"))
  212.   (format nil "~a" n))
  213.  
  214. ;(defconstant lcm sorry)
  215. ;(defconstant exp sorry)
  216. ;(defconstant tan sorry)
  217. ;(defconstant log sorry)
  218. ;(defconstant asin sorry)
  219. ;(defconstant acos sorry)
  220. ;(defconstant atan sorry)
  221.  
  222. ;(defconstant numerator sorry)
  223. ;(defconstant denominator sorry)
  224.  
  225. ; These are in EuLisp but have misfeatures in V0.37
  226.  
  227. ; (defun oddp (x) (not (evenp x)))
  228.  
  229. (defun memq (item x)        
  230.   (cond ((null x) '())
  231.         ((eq item (car x)) x)
  232.         (t (memq item (cdr x)))))
  233.  
  234. (defun reduce (f args)
  235.   (if (null (cdr args))
  236.       (car args)
  237.       (f (car args) 
  238.      (reduce f (cdr args)))))
  239.  
  240. (defun max args (reduce old-max args))
  241. (defun min args (reduce old-min args))
  242.  
  243. (defmacro make-stream-optional (name f)
  244.   `(defun ,name port
  245.      (,f (if port (car port) (standard-input-stream)))))
  246.  
  247. (make-stream-optional read     old-read)
  248. (make-stream-optional read-char old-read-char)
  249. (make-stream-optional peek-char old-peek-char)
  250.  
  251. ; Do renamings that couldn't be done above
  252.  
  253. (defconstant char? characterp)
  254. (defconstant procedure? functionp)
  255. (defconstant odd? oddp)
  256. (defconstant positivep positive?)
  257. (defconstant number->string number-to-string)
  258.  
  259. (defun substring (s i j)
  260.   (feel-substring s i (- j 1)))
  261.  
  262. (defun string-append-aux (strings)
  263.   (if (null? strings) ""
  264.     (feel-string-append (car strings) (string-append-aux (cdr strings)))))
  265.  
  266. (defun string-append strings
  267.   (string-append-aux strings))
  268.  
  269. (deflocal *case-diff* (- (char->integer #\a) (char->integer #\A)))
  270.  
  271. (defun char-upcase (x)
  272.   (cond
  273.     ((not (char-alphabetic-p x)) x)
  274.     ((char-upper-case-p x) x)
  275.     (else
  276.       (integer->char (- (char->integer x) *case-diff*)))))
  277.  
  278. (defun char-downcase (x)
  279.   (cond
  280.     ((not (char-alphabetic-p x)) x)
  281.     ((char-lower-case-p x) x)
  282.     (else
  283.       (integer->char (+ (char->integer x) *case-diff*)))))
  284.  
  285. ;(defconstant substring string-slice)    already renamed in V0.37
  286.  
  287. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  288.  
  289. ; Herald for this module appears here
  290.  
  291. (format t "Full Scheme module (development version).\n")
  292.  
  293. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  294.  
  295. ; Conditions
  296.  
  297. (defcondition scheme-error ())
  298. (defcondition schemedef-error ())
  299.  
  300. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  301. ;;;                                                          ;;;
  302. ;;;    D   E   F   I   N   I   T   I   O   N   S            ;;;
  303. ;;;                                                          ;;;
  304. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  305.  
  306. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  307.  
  308. ; define
  309.  
  310. (defun walk-body (body)
  311.   (if body
  312.       (if (and (consp (car body))
  313.                (equal (caar body) 'define))
  314.           (cons (list (if (consp (cadar body))
  315.                           (car (cadar body))
  316.                           (cadar body))
  317.                       ''unassigned)
  318.                 (walk-body (cdr body)))
  319.           (walk-body (cdr body)))
  320.       nil))
  321.  
  322. ;; Broken!!!
  323.  
  324. '(defmacro define (bind . values)
  325.   (if (consp bind)
  326.       (let ((name (car bind))
  327.         (args (cdr bind)))
  328.        (if (symbolp name)
  329.            `(progn (setq ,name
  330.                  (let ,(walk-body values)
  331.                   (lambda ,args ,@ values)))
  332.                ',name)
  333.            (eulisp-error "define: bad syntax" schemedef-error)))
  334.       (if (symbolp bind)
  335.       (if values
  336.           (if (and (consp (car values))
  337.                (equal (caar values) 'lambda))
  338.           `(progn (setq ,bind
  339.                 (let ,(walk-body (cddr (car values)))
  340.                      ,(car values)))
  341.               ',bind)
  342.           `(progn (setq ,bind ,(car values))
  343.               ',bind))
  344.           `(progn (setq ,bind 'unassigned) 
  345.               ',bind))
  346.       (eulisp-error "define: bad identifier" schemedef-error))))
  347.  
  348. ;; Fixed!!
  349.  
  350. (defmacro define (bind . values)
  351.   (if (consp bind)
  352.       (let ((name (car bind))
  353.         (args (cdr bind)))
  354.        (if (symbolp name)
  355.            `(progn (setq ,name
  356.                  (lambda ,args 
  357.                    (let ,(walk-body values)
  358.                  ,@values)))
  359.                ',name)
  360.            (eulisp-error "define: bad syntax" schemedef-error)))
  361.       (if (symbolp bind)
  362.       (if values
  363.           (if (and (consp (car values))
  364.                (equal (caar values) 'lambda))
  365.           `(progn (setq ,bind
  366.                 (let ,(walk-body (cddr (car values)))
  367.                      ,(car values)))
  368.               ',bind)
  369.           `(progn (setq ,bind ,(car values))
  370.               ',bind))
  371.           `(progn (setq ,bind 'unassigned) 
  372.               ',bind))
  373.       (eulisp-error "define: bad identifier" schemedef-error))))
  374.  
  375. ; letd is a let which understands local defines
  376.  
  377. (defmacro letd (bind . body)
  378.   (let ((bindings (walk-body body)))
  379.        (if bindings
  380.        `(let ,bindings
  381.          (let ,bind ,@body))
  382.        `(let ,bind ,@body))))
  383.  
  384. (export letd)
  385.  
  386. (defmacro set! (bind val) `(setq ,bind ,val))
  387. (defmacro begin forms `(progn ,@forms))
  388.  
  389. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  390.  
  391. ; Streams
  392.  
  393. (defconstant the-empty-stream nil)
  394.  
  395. (defmacro cons-stream (a b) `(cons ,a (delay ,b)))
  396.  
  397. (defun head (s) (car s))
  398.  
  399. (defun tail (s) (force (cdr s)))
  400.  
  401. (defun force (promise) (promise))
  402.  
  403. (defun empty-stream? (s) (eq s the-empty-stream))
  404.  
  405. (defmacro freeze (form) `(lambda () ,form))
  406.  
  407. (defmacro delay (form) `(make-promise (freeze ,form)))
  408.  
  409. (defun make-promise (p)
  410.   (let ((run-flag nil) (value nil))
  411.        (lambda ()
  412.            (if run-flag
  413.            value
  414.            (progn (setq run-flag t)
  415.               (setq value (p)))))))
  416. ; hack
  417.  
  418. (defconstant else t) 
  419.  
  420. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  421.  
  422. ; Simple ones
  423.  
  424. (defun inc (x) (+ x 1))    ; replaces 1+
  425. (defun dec (x) (- x 1))    ; replaces -1+
  426.  
  427. ; in V0.37, (equal nil 'nil) is false
  428. (defun boolean? (x) (if (or (eq x t) (eq x nil) (eq x 'nil)) t nil))
  429.  
  430. (defun error (message value)
  431.   (eulisp-error message scheme-error 'error-value value))
  432.  
  433. ; we assume that EuLisp mapcar evaluates in order (though Scheme 
  434. ; mapcar doesn't have to)
  435. (defmacro for-each (proc . lists) 
  436.   `(progn (mapcar ,proc ,@lists) t))
  437.  
  438. (defconstant set-car! (setter car))
  439. (defconstant set-cdr! (setter cdr))
  440. (defconstant string-set! (setter string-ref))
  441. (defconstant vector-set! (setter vector-ref))
  442.  
  443. (defun call-with-current-continuation (f) (let/cc k (f k)))
  444.  
  445. (defun sqrt (x)
  446.   (labels ( (square (x) (* x x))
  447.         (average (x y) (/ (+ x y) 2.0))
  448.         (good-enough? (guess)
  449.               (< (abs (- (square guess) x)) .001))
  450.         (improve (guess)
  451.              (average guess (/ x guess)))
  452.         (iter (guess)
  453.           (if (good-enough? guess)
  454.               guess
  455.               (sqrt-iter (improve guess)))))
  456.       (iter 1.0)))
  457.  
  458. (defun list? (l)
  459.   (if (null l)
  460.       t
  461.       (if (consp l)
  462.       (list? (cdr l))
  463.       nil)))
  464.  
  465. ; files
  466.  
  467. (defun open-input-file (filename) (open filename 'input))
  468. (defun open-output-file (filename) (open filename 'output))
  469. (defun close-input-port (port) (close port))
  470. (defun close-output-port (port) (close port))
  471.  
  472. ; BTW how do these interact with signals, call/cc etc?
  473. (defun call-with-input-file (filename f)
  474.   (let ((port (open filename 'input)) (value '()))
  475.        (setq value (f port))
  476.        (close port)
  477.        value))
  478.  
  479. (defun call-with-output-file (filename f)
  480.   (let ((port (open filename 'output)) (value '()))
  481.        (setq value (f port))
  482.        (close port)
  483.        value))
  484.  
  485. (defun with-input-from-file (file thunk)
  486.   (let ((old-stream standard-input-stream))
  487.        (let ((new-stream (open filename 'input)) (value))
  488.         ((setter standard-input-stream) new-stream)
  489.         (set! value (thunk))
  490.         (close new-stream)
  491.         ((setter standard-input-stream) old-stream)
  492.         value)))
  493.  
  494. (defun with-output-to-file (file thunk)
  495.   (let ((old-stream standard-output-stream))
  496.        (let ((new-stream (open filename 'output)) (value))
  497.         ((setter standard-output-stream) new-stream)
  498.         (set! value (thunk))
  499.         (close new-stream)
  500.         ((setter standard-output-stream) old-stream)
  501.         value)))
  502.  
  503. (defun char-ready? port
  504.   (stream-ready-p (if port (car port) (standard-input-stream))))
  505.  
  506. ; type predicates
  507.  
  508. (defun integer? (x) (eq (class-of x) integer))
  509. (defun real? (x) (eq (class-of x) real))
  510. (defun rational? (x) (eq (class-of x) rational))
  511. (defun complex? (x) (eq (class-of x) complex))
  512.  
  513. ;(defun string? (x) (eq (class-of x) string))
  514. ;(defun symbol? (x) (eq (class-of x) symbol))
  515. ;(defun vector? (x) (eq (class-of x) vector))
  516. ;(defun pair? (x) (eq (class-of x) pair))
  517. ;(defun number? (x) (subclassp (class-of x) number))
  518.  
  519. (defun list->string (l)
  520.   (let ((str (make-string (length l))))
  521.     (let loop ((l l) (i 0))
  522.       (unless (null? l)
  523.         (string-set! str i (car l))
  524.     (loop (cdr l) (+ i 1))))
  525.     str))
  526.  
  527. (defun string->list (s)
  528.   (let ((len (length s)))
  529.     (let loop ((i 0))
  530.       (if (= i len) '()
  531.     (cons (string-ref s i) (loop (+ 1 i)))))))
  532.  
  533. (defun string args
  534.   (list->string args))
  535.  
  536. (deflocal list->vector (converter (class-of #(1))))
  537. (deflocal vector->list (converter (class-of '(1))))
  538.  
  539. (defun vector stuff
  540.   (list->vector stuff))
  541.  
  542. ; Still have these to define...
  543.  
  544. ; assv
  545. ; case
  546. ; catch and throw
  547. ; char-upcase etc
  548. ; do
  549. ; memv
  550. ; rationalize
  551. ; string stuff (including string, string->number)
  552. ; transcript
  553. ; vector stuff (including vector)
  554.  
  555. (defun memv (a l) (member? a l eqv?))
  556. (defun assv (a l) (assq a l))
  557.  
  558. (export memv assv)
  559.  
  560. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  561. ;;;                                                          ;;;
  562. ;;;    E    X    P    O    R    T    S                      ;;;
  563. ;;;                                                          ;;;
  564. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  565.  
  566. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  567.  
  568. ; EuLisp names which don't need renaming
  569.  
  570. (export 
  571.       <
  572.       <=
  573.       >
  574.       >=
  575.       =
  576.       +
  577.       -
  578.       *
  579.       /
  580.           abs 
  581.       and
  582.       append
  583.       apply
  584.       assoc
  585.       assq
  586.       asin
  587.       acos
  588.       atan
  589.       car
  590.       cdr
  591.       caar
  592.       cadr
  593.       cdar
  594.       cddr
  595.       caaar
  596.       caadr
  597.       cadar
  598.       caddr
  599.       cdaar
  600.       cdadr
  601.       cddar
  602.       cdddr
  603.       caaaar
  604.       caaadr
  605.       caadar
  606.       caaddr
  607.       cadaar
  608.       cadadr
  609.       caddar
  610.       cadddr
  611.       cdaaar
  612.       cdaadr
  613.       cdadar
  614.       cdaddr
  615.       cddaar
  616.       cddadr
  617.       cdddar
  618.       cddddr
  619.       ceiling
  620.       char-upcase
  621.       char-downcase
  622.       cond
  623.       cons
  624.       cos
  625.       exp
  626.       expt
  627.       denominator
  628.       floor
  629.           gcd
  630.       lcm
  631.       length
  632.       let
  633.       let*
  634.       list
  635.       list-ref
  636.       log
  637.       make-string
  638.       make-vector
  639.       max
  640.       min
  641.       member
  642.       memq
  643.       modulo
  644.       newline
  645.       not
  646.       numerator
  647.       or
  648.       peek-char
  649.       print
  650.       quasiquote
  651.       quotient
  652.       read
  653.       read-char
  654.       remainder
  655.       reverse
  656.       round
  657.       sin
  658.       string-copy
  659.       string-length
  660.       string-ref
  661.       tan
  662.       truncate
  663.       vector-length
  664.       vector-ref
  665.       write
  666. )
  667.  
  668. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  669.  
  670. ; EuLisp functions renamed to Scheme in this module
  671. ; NB This renaming can be done here, on export, but currently
  672. ; appears at the top of the file (as I don't know how to do it
  673. ; on export!)
  674.  
  675. (export
  676.     char?
  677.     char=?
  678.     char<?
  679.     char>?
  680.     char<=?
  681.     char>=?
  682.     char->integer
  683.     current-input-port
  684.     current-output-port
  685.     display
  686.     eof-object?
  687.     eq?
  688.     equal?
  689.     even?
  690.     input-port?
  691.     integer->char
  692.     last-pair
  693.     length
  694.     letrec
  695.     list->string
  696.     list->vector
  697.     map
  698.     null?
  699.     number?
  700.     number->string
  701.     odd?
  702.     output-port?
  703.     pair?
  704.     procedure?    
  705.     string?
  706.     string-append
  707.     string->list
  708.     string->symbol
  709.     substring
  710.     symbol?
  711.     symbol->string
  712.     vector?
  713.     vector->list
  714.     zero?
  715. )
  716.  
  717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  718.  
  719. ; Scheme functions defined in this module
  720.  
  721. (export 
  722.     inc ; in place of 1+
  723.     dec ; in place of -1+
  724.  
  725.     begin 
  726.     boolean?
  727.     call-with-current-continuation
  728.     call-with-input-file
  729.     call-with-output-file
  730.     char-ready?
  731.     close-input-port 
  732.     close-output-port
  733.     complex?
  734.     cons-stream
  735.     define 
  736.     delay 
  737.         else    ; ho hum
  738.     empty-stream? 
  739.     error 
  740.     for-each
  741.     force
  742.     freeze
  743.     head 
  744.     integer? 
  745.     last-pair
  746.     list? 
  747.     ;load    this has to be in scheme module (to use eval/cm)
  748.     make-promise 
  749.     open-input-file 
  750.     open-output-file
  751.     rational?
  752.     real? 
  753.     set!     ; could be a renaming of setq if we could rename specials
  754.     set-car! 
  755.     set-cdr! 
  756.     sqrt    ; should this be in EuLisp?
  757.     string
  758.     string-set!
  759.     string->list
  760.     tail 
  761.     the-empty-stream
  762.     vector-set!
  763.     vector
  764.     with-input-from-file
  765.     with-output-to-file
  766. )
  767.  
  768. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  769.  
  770. ; Abelson and Sussman compatibility
  771.  
  772. ;(defun atom? (x) (not (consp x))) 
  773. ; actually, V0.37 has atom but it ain't in EuLisp
  774. (defconstant atom? atom)
  775.  
  776. (defconstant princ prin)
  777.  
  778. (export atom? princ print)
  779.  
  780. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  781.  
  782. ; Compatability with old Schemes
  783.  
  784. (defconstant prin1 write)
  785. (defconstant call/cc call-with-current-continuation)
  786. (defmacro sequence forms `(progn ,@forms))
  787.  
  788. (export prin1 call/cc sequence)
  789.  
  790. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  791.  
  792. ;; Real bozo hack at the number system...
  793.  
  794. (defun exact? (x) 
  795.   (cond
  796.     ((eq? (class-of x) integer) t)
  797.     ((eq? (class-of x) real) ())
  798.     (else ())))
  799.  
  800. (defun inexact? (x) 
  801.   (cond
  802.     ((eq? (class-of x) integer) ())
  803.     ((eq? (class-of x) real) t)
  804.     (else ())))
  805.  
  806. (defun exact->inexact (x) (* 1.0 x))
  807. (defun inexact->exact (x) (floor x))
  808.  
  809. (defun positive? (x) (> x 0))
  810.  
  811. (export exact? inexact? positive? exact->inexact inexact->exact)
  812.  
  813. (defun write-char (c . port)
  814.   (feel-write-char c (if (null? port) (current-output-port) (car port))))
  815.  
  816. (export write-char)
  817.  
  818. (defun list-tail (l n)
  819.   (if (= n 0) l (list-tail (cdr l) (- n 1))))
  820.  
  821. (export list-tail)
  822.  
  823. (defun flush-output stuff
  824.   (flush (if (null? stuff) (current-output-port) (car stuff))))
  825.  
  826. (export flush-output)
  827.  
  828. (defun last-pair (l)
  829.   (cond
  830.     ((not (pair? l)) (error "last-pair: bogus arg dude!" clock-tick))
  831.     ((not (pair? (cdr l))) l)
  832.     (else (last-pair (cdr l)))))
  833.  
  834. ;; Hacks...
  835.  
  836. (defstruct <ovector> () 
  837.   ((vector initarg vector accessor ovector-vector))
  838.   constructor (make-ovector-obj vector)
  839.   predicate ovector?)
  840.  
  841. (define (ovector . stuff)
  842.   (make-ovector-obj (apply vector stuff)))
  843.  
  844. (define (make-ovector size init)
  845.   (make-ovector-obj (make-vector size init)))
  846.  
  847. (define (ovector-ref v i)
  848.   (vector-ref (ovector-vector v) i))
  849.  
  850. (define (ovector-set! v i val)
  851.   (vector-set! (ovector-vector v) i val)
  852.   val)
  853.  
  854. (export ovector? ovector make-ovector ovector-ref ovector-set!)
  855.  
  856. (defconstant $t t)
  857. (defconstant $f '())
  858.  
  859. (export $t $f)
  860.  
  861. )
  862. ; end of newschemedef.em
  863.